/**
 * Created by Administrator on 2016/8/30.
 */

function IsTest() {
  return false;
}
//获取链接传入参数
function GetRequest() {
  var url = location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("&");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
    }
  }
  return theRequest;
}

//获取随机数
function GetRandom(n) {
  return Math.floor(Math.random() * n + 1)
}

//获取token
function GetToken(callBack) {
  //var myToken = sessionStorage.token;
  //if (myToken == undefined){
  //读取数据
  var info = JSON.parse(window.localStorage ? localStorage.getItem("userInfo") : Cookie.read("userInfo"));
  var msg = {};
  msg.userId = info.userId;
  msg.session = info.session;
  sessionStorage.userId = info.userId;
  
  $.post("api/get_token", {"data": JSON.stringify(msg)},
    function (jsonStruct) {
      var jsonObj = JSON.parse(jsonStruct["data"]);
      if (jsonObj.status == "200000") {
        sessionStorage.token = jsonObj.token;
        callBack(sessionStorage.userId, sessionStorage.token);
      }
      else {
        alert("请重新登陆");
        GoLoginPage();
      }
    })
  //}
  
}

//删除token
function RemoveToken() {
  var msg = {};
  msg.userId = sessionStorage.userId;
  msg.token = sessionStorage.token;
  sessionStorage.clear();
  $.post("api/remove_token", {"data": JSON.stringify(msg)}, function (e) {
    
  });
}

module.exports = {}

